home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / flonum-c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  2.4 KB  |  75 lines

  1. /* flonum_copy.c - */
  2.  
  3. /* Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of Gas, the GNU Assembler.
  6.  
  7. The GNU assembler is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU Assembler General
  12. Public License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. the GNU Assembler, but only under the conditions described in the
  16. GNU Assembler General Public License.  A copy of this license is
  17. supposed to have been given to you along with the GNU Assembler
  18. so you can know your rights and responsibilities.  It should be
  19. in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.  */
  21.  
  22. #include "flonum.h"
  23.  
  24. void
  25. flonum_copy (in, out)
  26.      FLONUM_TYPE *    in;
  27.      FLONUM_TYPE *    out;
  28. {
  29.   int            in_length;    /* 0 origin */
  30.   int            out_length;    /* 0 origin */
  31.  
  32.   out -> sign = in -> sign;
  33.   in_length = in  -> leader - in -> low;
  34.   if (in_length < 0)
  35.     {
  36.       out -> leader = out -> low - 1; /* 0.0 case */
  37.     }
  38.   else
  39.     {
  40.       out_length = out -> high - out -> low;
  41.       /*
  42.        * Assume no GAPS in packing of littlenums.
  43.        * I.e. sizeof(array) == sizeof(element) * number_of_elements.
  44.        */
  45.       if (in_length <= out_length)
  46.     {
  47.       {
  48.         /*
  49.          * For defensive programming, zero any high-order littlenums we don't need.
  50.          * This is destroying evidence and wasting time, so why bother???
  51.          */
  52.         if (in_length < out_length)
  53.           {
  54.         bzero ((char *)(out->low + in_length + 1), out_length - in_length);
  55.           }
  56.       }
  57.       bcopy ((char *)(in->low), (char *)(out->low), (int)((in_length + 1) * sizeof(LITTLENUM_TYPE)));
  58.       out -> exponent = in -> exponent;
  59.       out -> leader   = in -> leader - in -> low + out -> low;
  60.     }
  61.       else
  62.     {
  63.       int    shorten;        /* 1-origin. Number of littlenums we drop. */
  64.  
  65.       shorten = in_length - out_length;
  66.       /* Assume out_length >= 0 ! */
  67.       bcopy ((char *)(in->low + shorten),(char *)( out->low), (int)((out_length + 1) * sizeof(LITTLENUM_TYPE)));
  68.       out -> leader = out -> high;
  69.       out -> exponent = in -> exponent + shorten;
  70.     }
  71.     }                /* if any significant bits */
  72. }
  73.  
  74. /* end: flonum_copy.c */
  75.